#!/bin/sh

#--------------------------------------------------------------------
# Network Utilities
#--------------------------------------------------------------------

case "$fn" in

    # Internet connection speed test
    "speedtest")
          echo "Testing internet connection speed..."
          networkQuality -v
    ;;


    # List of used ports
    "ports")

        echo "Getting list of used ports..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}sudo lsof -iTCP -sTCP:LISTEN -P\n\n${NC}"
        fi
        sudo lsof -iTCP -sTCP:LISTEN -P
    ;;


    # Get local IP address
    "ip:local")

        local_ip=$(ipconfig getifaddr en0)
        if [ $? == 0 ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}ipconfig getifaddr en0\n\n${NC}"
            fi
        else
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}ipconfig getifaddr en1\n\n${NC}"
            fi
            local_ip=$(ipconfig getifaddr en1)
        fi
        echo "Your IP address is:\n${local_ip}"
    ;;


    # Get public IP address
    "ip:public")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}wget http://ipinfo.io/ip -qO -\n\n${NC}"
        fi
        wget http://ipinfo.io/ip -qO -
    ;;

esac
